package com.itheima.kafka.boot;

import com.alibaba.fastjson.JSON;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.Optional;

@Component
public class HelloListener {

    @KafkaListener(topics = "kafka-hello")
    public void receiverMessage(ConsumerRecord<?,?> record){
        if (Optional.ofNullable(record).isPresent()){
            System.out.println("record.value() = " + record.value());
        }
    }

    @KafkaListener(topics = "map-topic")
    public void receive(ConsumerRecord<?,?> record){
        if (Optional.ofNullable(record).isPresent()){
            System.out.println(record.value());
            System.out.println("------------------------------");
            Map map = JSON.parseObject((String) record.value(), Map.class);
            System.out.println(map);
        }
    }
}
